<template>
  <div class="timeDowns">
    <span class="kk">{{ times }}</span>
  </div>
</template>

<script>
export default {
  components: {},
  props: {
    start: {
      type: String,
      default: "",
    },
    end: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      timer: null,
      times:"--天--:--:--",
    };
  },
  mounted() {
    this.timeDown();
  },
  methods: {
   timeDown() { // 倒计时
			
				clearInterval(this.timer);
				var starttime = new Date(this.start.replace(/-/g, "/")) / 1000;
				var nowDate = Math.round(new Date() / 1000); // 当前时间
				//var endtime = Number(this.initActiveMsgObj.end_time); 
				var endtime = new Date(this.end.replace(/-/g, "/")) / 1000;
				// endtime = Math.round(new Date('2019/7/10 14:56:00') / 1000); + 60;
				if (endtime < nowDate) {
					return
				}
			
			
				var totalSeconds = parseInt((endtime - nowDate)); // 相差的总秒数
				//天数
				var days = Math.floor(totalSeconds / (60 * 60 * 24));
				//取模（余数）
				var modulo = totalSeconds % (60 * 60 * 24);
				//小时数
				var hours = Math.floor(modulo / (60 * 60));
				hours = hours < 10 ? ('0' + hours) : hours;
				modulo = modulo % (60 * 60);
				//分钟
				var minutes = Math.floor(modulo / 60);
				minutes = minutes < 10 ? '0' + minutes : minutes;
				// console.log(minutes)
				//秒
				var seconds = modulo % 60;
				seconds = seconds < 10 ? '0' + seconds : seconds;
				// console.log(seconds);
				//输出到页面
				this.times = days + '天' +hours + ':' + minutes + ':' + seconds;
				// console.log(days + "天" + hours + "时" + minutes + "分");
				//if(totalSeconds <= 0){
				if (totalSeconds <= 60) {
					clearInterval(this.timer);
					// window.location.reload()
				} else {
					this.timer = setInterval(this.timeDown, 1000);
				}
			},
  },
};
</script>

<style scoped lang="scss">
.timeDowns {
  .kk {
    display: inline-block;
    vertical-align: middle;
    width: auto;
    // border-radius: 0.5rem;
    padding: 0.5rem 0rem;
    font-weight: 400;
    color: #ffffff;
  }
}
</style>
